package com.report.utils;

import cn.hutool.core.util.ObjectUtil;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/5 22:50
 */
public class LocalDateUtils {

    public static LocalDate plusDays(Integer days) {

        return LocalDate.now().plusDays(days);

    }

    public static long day(LocalDate localDate) {
        if(ObjectUtil.isEmpty(localDate)) {
            return 0;
        }
        return ChronoUnit.DAYS.between(LocalDate.now(), localDate);
    }




    public static LocalDate add(LocalDate startDate, LocalDate endDate) {
        if(ObjectUtil.isEmpty(startDate)) {
            return endDate;
        }
        long day = day(startDate);
        endDate.plusDays(day);
        return endDate;
    }

    public static Long getRemainSecondsOneDay(Date currentDate) {
        //使用plusDays加传入的时间加1天，将时分秒设置成0
        LocalDateTime midnight = LocalDateTime.ofInstant(currentDate.toInstant(),
                        ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
                .withSecond(0).withNano(0);
        LocalDateTime currentDateTime = LocalDateTime.ofInstant(currentDate.toInstant(),
                ZoneId.systemDefault());
        System.out.println(ChronoUnit.HOURS.between(currentDateTime, midnight));
        //使用ChronoUnit.SECONDS.between方法，传入两个LocalDateTime对象即可得到相差的秒数
        //long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
        return ChronoUnit.HOURS.between(currentDateTime, midnight);
    }

    public static List<LocalDate> dateLists(){
        List<LocalDate> list = new ArrayList<>();
        LocalDate date = LocalDate.now();
        int numberOfDays = date.lengthOfMonth();
        for (int i = 1; i <= numberOfDays; i++) {
            LocalDate currentDate = LocalDate.of(date.getYear(), date.getMonth(), i);
            System.out.println(currentDate);
            list.add(currentDate);
        }
        return list;
    }

    public static List<LocalDate> beforeDate(){
        LocalDate currentDate = LocalDate.now();
        List<LocalDate> list = new ArrayList<>();
        LocalDate oneMonthAgo = currentDate.minusMonths(1);
        while (oneMonthAgo.isBefore(currentDate)) {
            oneMonthAgo = oneMonthAgo.plusDays(1);
            list.add(oneMonthAgo);
        }
        return list;
    }

    public static void main(String[] args) {


    }

}
